package com.naizhuai.util;

import android.content.Context;

import com.yanzhenjie.album.Album;
import com.yanzhenjie.album.AlbumFile;
import com.yanzhenjie.album.Filter;

import java.util.List;

import rx.subjects.PublishSubject;

/**
 * @author：lichenxi
 * @date 2018/4/19 23
 * email：525603977@qq.com
 * Fighting
 */
public class AlbumUtils {
    private static final int selectImg = 1;
    public static  PublishSubject<AlbumFile> multipleChoice(Context context,int limitCount){
        PublishSubject<AlbumFile> subject=PublishSubject.create();
        Album.image(context).multipleChoice()
                .requestCode(selectImg)
                .filterMimeType(attributes -> attributes.contains("gif"))
                .afterFilterVisibility(false)
                .columnCount(3)
                .selectCount(limitCount)
                .onResult((requestCode, result) -> {
                    for (AlbumFile albumFile : result)
                           subject.onNext(albumFile);
                    subject.onCompleted();
                }).start();
        return subject;
    }

    public static PublishSubject<List<AlbumFile>> multipleListChoice(Context context, int limitCount) {
        PublishSubject<List<AlbumFile>> subject = PublishSubject.create();
        Album.image(context).multipleChoice()
                .requestCode(selectImg)
                .columnCount(3)
                .filterMimeType(attributes -> attributes.contains("gif"))
                .afterFilterVisibility(false)
                .selectCount(limitCount)
                .onResult((requestCode, result) -> {
                    subject.onNext(result);
                    subject.onCompleted();
                }).start();
        return subject;
    }
   public static PublishSubject<AlbumFile> multipleChoice(Context context){
        return  multipleChoice(context,Integer.MAX_VALUE);
   }
    public static  PublishSubject<AlbumFile> singleChoice(Context context){
        PublishSubject<AlbumFile> subject=PublishSubject.create();
        Album.image(context).singleChoice()
                .requestCode(selectImg)
                .columnCount(3)
                .filterMimeType(attributes -> attributes.contains("gif"))
                .afterFilterVisibility(false)
                .onResult((requestCode, result) -> {
                    for (AlbumFile albumFile : result)
                        subject.onNext(albumFile);
                    subject.onCompleted();
                }).start();
        return subject;
    }

}
